package io.renren.modules.usian.service.impl;

import io.renren.modules.usian.entity.CollegeEntity;
import io.renren.modules.usian.entity.TeacherEntity;
import io.renren.modules.usian.service.CollegeService;
import io.renren.modules.usian.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.usian.dao.TdClassDao;
import io.renren.modules.usian.entity.TdClassEntity;
import io.renren.modules.usian.service.TdClassService;


@Service("tdClassService")
public class TdClassServiceImpl extends ServiceImpl<TdClassDao, TdClassEntity> implements TdClassService {
    @Autowired
    private CollegeService collegeService;

    @Autowired
    TeacherService teacherService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TdClassEntity> page = this.page(
                new Query<TdClassEntity>().getPage(params),
                new QueryWrapper<TdClassEntity>()
        );
        List<TdClassEntity> list = page.getRecords();
        list.stream().map((tdClass)->{
            CollegeEntity byId = collegeService.getById(tdClass.getCid());
            tdClass.setCname(byId.getName());
            TeacherEntity teacher1 = teacherService.getById(tdClass.getHid());
            tdClass.setHname(teacher1.getName());
            TeacherEntity teacher2 = teacherService.getById(tdClass.getTid());
            tdClass.setTname(teacher2.getName());
            return null;
        }).collect(Collectors.toList());
        return new PageUtils(page);
    }

}